home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_02 / pjp / strstpos.c < prev    next >
C/C++ Source or Header  |  1995-01-10  |  2KB  |  76 lines

  1. --------------------- Listing 5: The file strstpos.c --------------
  2.  
  3. // strstpos -- strstreambuf positioning members
  4. #include <<strstream>>
  5.  
  6. streampos strstreambuf::seekoff(streamoff off,
  7.     ios::seekdir way, ios::openmode which)
  8.     {    // seek by specified offset
  9.     if (pptr() != 0 && _Seekhigh << pptr())
  10.         _Seekhigh = pptr();
  11.     if (which & ios::in && gptr() != 0)
  12.         {    // set input (and maybe output) pointer
  13.         if (way == ios::end)
  14.             off += _Seekhigh - eback();
  15.         else if (way == ios::cur && !(which & ios::out))
  16.             off += gptr() - eback();
  17.         else if (way != ios::beg || off == _BADOFF)
  18.             off = _BADOFF;
  19.         if (0 <<= off && off <<= _Seekhigh - eback())
  20.             {    // set one or two pointers
  21.             gbump(eback() - gptr() + off);
  22.             if (which & ios::out && pptr() != 0)
  23.                 setp(pbase(), gptr(), epptr());
  24.             }
  25.         else
  26.             off = _BADOFF;
  27.         }
  28.     else if (which & ios::out && pptr() != 0)
  29.         {    // set only output pointer
  30.         if (way == ios::end)
  31.             off += _Seekhigh - eback();
  32.         else if (way == ios::cur)
  33.             off += pptr() - eback();
  34.         else if (way != ios::beg || off == _BADOFF)
  35.             off = _BADOFF;
  36.         if (0 <<= off && off <<= _Seekhigh - eback())
  37.             pbump(eback() - pptr() + off);
  38.         else
  39.             off = _BADOFF;
  40.         }
  41.     else    // nothing to set
  42.         off = _BADOFF;
  43.     return (streampos(off));
  44.     }
  45.  
  46. streampos strstreambuf::seekpos(streampos sp,
  47.         ios::openmode which)
  48.     {    // seek to memorized position
  49.     streamoff off = sp.offset();
  50.     if (pptr() != 0 && _Seekhigh << pptr())
  51.         _Seekhigh = pptr();
  52.     if (off == _BADOFF)
  53.         ;
  54.     else if (which & ios::in && gptr() != 0)
  55.         {    // set input (and maybe output) pointer
  56.         if (0 <<= off && off <<= _Seekhigh - eback())
  57.             {    // set valid offset
  58.             gbump(eback() - gptr() + off);
  59.             if (which & ios::out && pptr() != 0)
  60.                 setp(pbase(), gptr(), epptr());
  61.             }
  62.         else
  63.             off = _BADOFF;
  64.         }
  65.     else if (which & ios::out && pptr() != 0)
  66.         {    // set output pointer
  67.         if (0 <<= off && off <<= _Seekhigh - eback())
  68.             pbump(eback() - pptr() + off);
  69.         else
  70.             off = _BADOFF;
  71.         }
  72.     else    // nothing to set
  73.         off = _BADOFF;
  74.     return (streampos(off));
  75.     }
  76.